/*********************************************************************************
  *FileName:  nsuc16xx_adc.h
  *Version:   V1.0
  *Date:      2023-09-21
**********************************************************************************/
#ifndef  __nsuc16xx_adc_H__
#define  __nsuc16xx_adc_H__


/***************************************Includes***********************************/
#include "nsuc16x0.h"

/***************************************Macros***********************************/
#define ADC_ClockSource_32M                 ((uint8_t)0x00)
#define ADC_ClockSource_16M                 ((uint8_t)0x01)
#define ADC_ClockSource_8M                  ((uint8_t)0x02)
#define ADC_ClockSource_4M                  ((uint8_t)0x03)
#define ADC_ClockSource_2M                  ((uint8_t)0x04)
#define ADC_ClockSource_1M                  ((uint8_t)0x05)
#define ADC_ClockSource_500K                ((uint8_t)0x06)
#define ADC_ClockSource_250K                ((uint8_t)0x07)
#define ADC_ClockSource_125K                ((uint8_t)0x08)

#define ADC_TrigSource_Software             ((uint8_t)0x00)
#define ADC_TrigSource_EPWM0                ((uint8_t)0x01)
#define ADC_TrigSource_EPWM1                ((uint8_t)0x02)
#define ADC_TrigSource_EPWM2                ((uint8_t)0x03)
#define ADC_TrigSource_EPWM3                ((uint8_t)0x04)
#define ADC_TrigSource_TIMER                ((uint8_t)0x05)
#define ADC_TrigSource_EPWM0123             ((uint8_t)0x06)
#define ADC_TrigSource_Software_EOC         ((uint8_t)0x07)

#define ADC_VRef_Internal                   ((uint8_t)0x00)
#define ADC_VRef_External                   ((uint8_t)0x01)
#define ADC_VRef_AVDD                       ((uint8_t)0x02)

#define ADC_Channel_Reserved                ((uint8_t)0x00)
#define ADC_Channel_MVSS0                   ((uint8_t)0x01)
#define ADC_Channel_BVDD                    ((uint8_t)0x02)
#define ADC_Channel_STDA                    ((uint8_t)0x03)
#define ADC_Channel_STDB                    ((uint8_t)0x04)
#define ADC_Channel_TEMP                    ((uint8_t)0x05)
#define ADC_Channel_LINBSM                  ((uint8_t)0x06)
#define ADC_Channel_LGPIO0                  ((uint8_t)0x07)
#define ADC_Channel_LGPIO1                  ((uint8_t)0x08)
#define ADC_Channel_LGPIO2                  ((uint8_t)0x09)
#define ADC_Channel_LGPIO3                  ((uint8_t)0x0A)
#define ADC_Channel_LGPIO4                  ((uint8_t)0x0B)
#define ADC_Channel_LGPIO5                  ((uint8_t)0x0C)
#define ADC_Channel_LGPIO45                 ((uint8_t)0x0D)
#define ADC_Channel_AVSS                    ((uint8_t)0x0E)
#define ADC_Channel_VREF                    ((uint8_t)0x0F)

#define ADC_PGA_Gain_1                      ((uint8_t)0x00)
#define ADC_PGA_Gain_2                      ((uint8_t)0x01)
#define ADC_PGA_Gain_4                      ((uint8_t)0x02)
#define ADC_PGA_Gain_10                     ((uint8_t)0x03)
#define ADC_PGA_Gain_20                     ((uint8_t)0x04)
#define ADC_PGA_Gain_40                     ((uint8_t)0x05)
#define ADC_PGA_Gain_4_11                   ((uint8_t)0x06)
#define ADC_PGA_ByPass                      ((uint8_t)0x07)

#define ADC_Rank_Disable                    ((uint8_t)0x00)
#define ADC_Rank_Enable                     ((uint8_t)0x01)

#define ADC_IT_EOC                          ((uint32_t)0x01)
#define ADC_IT_TCOLL                        ((uint32_t)0x02)

#define ADC_ConvMode_Single                 ((uint8_t)0x00)
#define ADC_ConvMode_Difference             ((uint8_t)0x01)

#define ADC_Queue_Rank1                     ((uint8_t)0x00)
#define ADC_Queue_Rank2                     ((uint8_t)0x01)
#define ADC_Queue_Rank3                     ((uint8_t)0x02)
#define ADC_Queue_Rank4                     ((uint8_t)0x03)
#define ADC_Queue_Rank5                     ((uint8_t)0x04)
#define ADC_Queue_Rank6                     ((uint8_t)0x05)
#define ADC_Queue_Rank7                     ((uint8_t)0x06)
#define ADC_Queue_Rank8                     ((uint8_t)0x07)

/***************************************Variables***********************************/
typedef struct
{
    uint8_t ADC_ClockSource;
    uint8_t ADC_TrigSource;
    uint8_t ADC_OnDelayTimeCyecles;
    uint8_t ADC_StableTimeCyecles;
    uint8_t ADC_ConvTimeCyecles;
    uint8_t ADC_SampleTimeCyecles;
    uint8_t ADC_ConvMode;
    uint8_t ADC_RefVoltageSource;
} ADC_InitTypeDef;

/***************************************Functions***********************************/
void ADC_Init(ADC_TypeDef *ADCx, ADC_InitTypeDef *ADC_InitStruct);
void ADC_QueueConfig(ADC_TypeDef *ADCx, uint8_t ADC_QueueRank, uint8_t ADC_Channel, uint8_t ADC_PGA, uint8_t ADC_State);
void ADC_Cmd(ADC_TypeDef *ADCx, FunctionalState NewState);
void ADC_SoftwareStartConvCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
void ADC_ITConfig(ADC_TypeDef *ADCx, uint32_t ADC_IT, FunctionalState NewState);
ITStatus ADC_GetITStatus(ADC_TypeDef *ADCx, uint32_t ADC_IT);
void ADC_ClearITPendingBit(ADC_TypeDef *ADCx, uint32_t ADC_IT);
uint16_t ADC_GetQueueRankValue(ADC_TypeDef *ADCx, uint8_t ADC_Queue_Rank);

#endif
/* [] END OF nsuc16xx_adc.h */
